<template>
	<section id="setpwd">
		<HeaDer :Title='titleData'></HeaDer>
		<section class="setpwdWarp">
			<section class="title">
				<h2>重新设置密码</h2>
				<span class="alse">8-20个字符,不可以是纯数字或纯字母</span>
			</section>
			<section class="formWarp">
				<van-cell-group>
					<van-field v-model="userData.pw1" placeholder="请输入密码" :type='isShow.type' :icon="isShow.icon" @click-icon='switchs(1)' />
					<van-field v-model="userData.pw2" placeholder="请再次输入密码" :type='isShow.otype' :icon="isShow.oicon" @click-icon='switchs(2)' />
				</van-cell-group>

			</section>
			<section class="btnWarp" @click="submit">
				<section class="btn">
					重设密码
				</section>
			</section>
		</section>
	</section>
</template>

<script>
	import HeaDer from "../common/header.vue";
	export default {
		data() {
			return {
				//头部需要的数据
				titleData: {
					name: '',
					flat: 1
				},
				//要向后台发送的数据
				userData: {
					mobile: '',  //手机号
					pw1: '',   //密码
					pw2: '',
					code: ''   //验证码

				},
				//控制密码显隐和icon数据
				isShow: {
					icon: 'password-not-view',
					type: 'password',
					oicon: 'password-not-view',
					otype: 'password'
				}
			}
		},
		methods: {
			//密码显隐控制函数
			switchs(index) {
				this.$public.switchs(index, this);
			},
			//点击重新设置密码执行函数
			submit() {
				var _this = this;
				if(!_this.$public.pwd(_this.userData.pw1) || !_this.$public.pwd(_this.userData.pw2)) {
					_this.$toast('密码格式有误');
					return false;
				} else if(_this.userData.pw1 != _this.userData.pw2) {
					_this.$toast('两次输入密码不一致');
					return false
				}
				_this.$public.loading('设置中...',_this);  // loading
				_this.$http.post(_this.$host.reset_pwd, _this.userData).then(function(response) {
					_this.$toast(response.data.msg);
					if(response.data.status == 200) {
						_this.$public.go('login', 500, _this);
					} else {
						//清空数据
						_this.userData = {
							mobile: '',
							pw1: '',
							pwd2: '',
							code: ''
						}
					}

				}).catch(function() {})
			}
		},
		created:function(){
			var _this = this;
			_this.userData.code = _this.$route.query.code;
			_this.userData.mobile = sessionStorage.mobile;
		},
		components: {
			'HeaDer': HeaDer
		}
	}
</script>

<style>

</style>